﻿using System;
using System.Collections.Generic;
using NmbpProject2.DataLayer;
using NmbpProject2.DboClasses;

namespace NmbpProject2.BusinessLayer {

  internal class CompApplicationBL {

    private readonly CompApplicationDL _cDL = new CompApplicationDL ();

    public CompApplication findByPersonComp (Person person, Competition competition) {
      return _cDL.findByPersonComp (person, competition);
    }

    public List<CompApplication> getAllApplications () {
      return _cDL.getAllApplications ();
    }

    public void insertApplication (
        Person person,
        List<ProgLanguage> progLanguages,
        DateTime date,
        List<Category> categories,
        Competition competition) {
      _cDL.insertApplication (person, progLanguages, date, categories, competition);
    }

    public void delete (CompApplication application) {
      _cDL.delete (application);
    }

    public void delete (List<CompApplication> applications) {
      foreach (CompApplication application in applications) {
        delete (application);
      }
    }

    public void update (
        CompApplication application,
        Person person,
        List<ProgLanguage> progLanguages,
        DateTime date,
        List<Category> categories,
        Competition competition) {
      _cDL.update (application, person, progLanguages, date, categories, competition);
    }

    public bool exists (CompApplication application, Person person, Competition competition) {
      CompApplication existingApplication = _cDL.findByPersonComp (person, competition);
      if (existingApplication == null || existingApplication == application) {
        return false;
      }
      return true;
    }
  }
}